/*
 * JsonReader.h
 *
 *  Created on: Jun 11, 2011
 *      Author: ToanNhan
 */

#ifndef JSONREADER_H_
#define JSONREADER_H_

#include "FBase.h"
#include "JsonValue.h"
#include "JsonObject.h"
#include "JSonString.h"
#include "JsonArray.h"
#include "JsonNumber.h"
#include "JsonException.h"
#include "vector"

using namespace std;
using namespace Osp::Base;

class JsonReader {
private:
//	const String charKeeping = ",:";
protected:
	 static const int BUFFER_SIZE_MAX = 1024;
	/*
	 * return: the end index
	 */
	void readString(ByteBuffer *json, JsonValue *&jsonString);
	void readObject(ByteBuffer *json, JsonValue *&jsonObject);
	void readArray(ByteBuffer *json, JsonValue *&jsonArray);
	void readNumber(ByteBuffer *json, JsonValue *&jsonNumber);
	void readNext(ByteBuffer *json, JsonValue *&jsonValue);

	ByteBuffer* readBlockN(ByteBuffer *json, mchar beginChar, mchar endChar);

public:
	JsonReader();
	virtual ~JsonReader();

	void read(ByteBuffer *json, JsonObject &jsonObject);
	void read(ByteBuffer *json, JsonArray &jsonArray);
	void read(ByteBuffer *json, JsonString &jsonString);
	void test();
	JsonValue* readN(ByteBuffer *json);
};

#endif /* JSONREADER_H_ */
